import reqests from "../utils/requests.js"
import {STATUS_CODE} from "../utils/variables.js"

/**
 * 提交订单
 * @param {Object} data
 */
export async function submitOrderApi(data) {
	const res = await reqests.request({
		url: "/order/submit",
		data,
		method: "POST"
	})
	if(res.code!=STATUS_CODE.SUCCESS_CODE){
		uni.showToast({
			title:"，请稍后重试",
			icon:'none',
			duration:2000
		})
		return;
	}
	return res.data;
}


/**
 * 获取订单列表
 * @param {Object} data
 */
export async function getOrderListApi(data) {
	const res = await reqests.request({
		url: `/order`,
		data,
		method: "PUT"
	})
	if(res.code!=STATUS_CODE.SUCCESS_CODE){
		uni.showToast({
			title:"获取失败，请稍后重试",
			icon:'none',
			duration:2000
		})
		return;
	}
	return res.data;
}




/**
 * 根据商品Id 创建订单提交信息
 * @param {Object} data
 */
export async function getOrderDPayApi(goodsId) {
	const res = await reqests.request({
		url: `/order/create?goodsId=${goodsId}`,
		method: "GET"
	})
	if(res.code!=STATUS_CODE.SUCCESS_CODE){
		uni.showToast({
			title:"获取失败，请稍后重试",
			icon:'none',
			duration:2000
		})
		return;
	}
	return res;
}




/**
 * 根据Id 获取订单信息
 * @param {Object} data
 */
export async function getOrderDetailApi(data) {
	const res = await reqests.request({
		url: `/order/detail`,
		data,
		method: "PUT"
	})
	if(res.code!=STATUS_CODE.SUCCESS_CODE){
		uni.showToast({
			title:"获取失败，请稍后重试",
			icon:'none',
			duration:2000
		})
		return;
	}
	return res.data;
}
